﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon.ChildWindows;

namespace Baosight.ZNH.ZMCP.UI.PopWindows
{
    public partial class CrubReport : EFViewCmes
    {
        public CrubReport(string dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.spWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    this.fdDate.Value = DateTime.Now.ToString("yyyy-MM-dd");
                    this.fdCurrentDate.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    this.fdStatus.Value = "0";
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    this.fdDate.IsEnabled = false;
                    this.fdWorknumId.IsEnabled = false;
                    base.Mode = OperationMode.Update;
                    break;
                case "detail":
                    this.Commit.Visibility = Visibility.Collapsed;
                    this.Report.Visibility = Visibility.Collapsed;
                    BaseTools.EFDataFieldNotEnabled(this.spWindows.GetChildObjects<EFDataField>(null, true));
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick(this.eServiceName, sender, e);
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }

        /// <summary>
        /// 上报按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReportClick(object sender, RoutedEventArgs e)
        {
            this.fdStatus.Value = "1";
            base.OnCommitButtonClick(this.eServiceName, sender, e);
        }

        /// <summary>
        /// 选择工程带出 工程名称 工程地点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdProjectId_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            EFComboBox box = (sender as EFDataField).Content as EFComboBox;
            if (box.SelectedItem != null)
            {
                this.fdProjectName.Value = box.SelectedItem.GetType().GetProperty("fdName").GetValue(box.SelectedItem, null);
                this.fdProjectPlace.Value = box.SelectedItem.GetType().GetProperty("fdProjectPlace").GetValue(box.SelectedItem, null);
            }
        }

        /// <summary>
        /// 班组
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdGroupId_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            EFComboBox box = (sender as EFDataField).Content as EFComboBox;
            if (box.SelectedItem != null)
            {
                this.fdGroupLeader.Value = box.SelectedItem.GetType().GetProperty("Name").GetValue(box.SelectedItem, null);
            }
        }

    }
}


